<!doctype html>
<html lang="">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite App</title>
    <style></style>
  </head>
  <body>
    <div id="app">
      {{totalAge}}
      <div>
        <button @click="list[0].age++">{{list[0].name}}+1岁</button>
      </div>
      <div>
        <button @click="totalAge = 100">打印</button>
      </div>
    </div>
    <script src="./vue.js"></script>
    <script>
      new Vue({
        el: '#app',
        data: {
          list: [
            {
              id: 1,
              name: '张三',
              age: 30,
            },
            {
              id: 2,
              name: '李四',
              age: 25,
            },
            {
              id: 3,
              name: '王五',
              age: 35,
            },
          ],

          newName: '',
        },
        methods: {},
        computed: {
          // 简写
          /* totalAge() {
            return this.list.reduce((a, b) => a + b.age, 0)
          },
 */
          totalAge: {
            get() {
              console.log('打印 ---> ')
            },
            set() {},
          },
        },
      })
    </script>
  </body>
</html>
